package item.inkcloud.communityservice.controller;


import item.inkcloud.communityservice.entity.Article;
import item.inkcloud.communityservice.mapper.ArticleMapper;
import item.inkcloud.communityservice.pojo.BriefArticleInfo;
import item.inkcloud.communityservice.pojo.DetailedArticleInfo;
import item.inkcloud.communityservice.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;


@RequestMapping("/community")
@RestController
public class InfoController {

    @Autowired
    ArticleService articleService;

    @RequestMapping("/articleList")
    HashMap<String, Object> getArticleList(){

        ArrayList<BriefArticleInfo> articleList = articleService.getArticleList();
        HashMap<String,Object> resultMap = new HashMap<>();
        if(articleList!= null){
            resultMap.put("status",1);
            resultMap.put("data",articleList);
            return resultMap;

        }else {
            resultMap.put("status",0);
            return resultMap;
        }

    }


    @RequestMapping("/articleDetail")
    HashMap articleDetail(@RequestParam String articleId){

        DetailedArticleInfo article = articleService.getArticleDetail(articleId);
        HashMap<String,Object> resultMap = new HashMap<>();


        if(article != null){
            resultMap.put("status",1);
            resultMap.put("data",article);
            return resultMap;

        }else {
            resultMap.put("status",0);
            return resultMap;
        }

    }

}
